﻿@{
    Bundle("jquery_cookie");
    Bundle("jquery_validate");
    Bundle("ckeditor");
}

<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('@ID("#tabs")').tabs({
            cookie: {
                expires: 1
            }
        });
    });
</script>
<div id="@ID("tabs")">
    <ul>
        @foreach(var i in (Model.Translations as IEnumerable<dynamic>).OrderBy(x => x.Language.Code))
        {
            <li><a href="@ID("#tab_{0}", JDM.String(i.Language.Code))">@JDM.String(i.Language.Code)</a></li>
        }
        <li><a href="@ID("#tab_new")">+</a></li>
    </ul>
    @foreach(var i in (Model.Translations as IEnumerable<dynamic>).OrderBy(x => x.Language.Code))
    {
        <div id="@ID("tab_{0}", JDM.String(i.Language.Code))">
            <script type="text/javascript">
                jQuery(document).ready(function () {
                    jQuery('@ID("#form_{0}", JDM.String(i.Language.Code))').validate({
                        rules: {
                            title: {
                                required: true
                            }
                        }
                    });
                    jQuery('@ID("#txt_text_{0}", JDM.String(i.Language.Code))').ckeditor({
                        fillSpace: true,
                        autoHeight: false
                    });
                });
            </script>
            <form id="@ID("form_{0}", JDM.String(i.Language.Code))" class="common-form" action="@Url.Action(Loc.Act("UpdateTranslation").Localized())" method="post">
                <input type="hidden" name="id" value="@JDM.Int32(i.EntityID)" />
                <input type="hidden" name="postID" value="@JDM.Int32(Model.EntityID)" />
                <input type="hidden" name="languageID" value="@JDM.Int32(i.Language.EntityID)" />
                <table>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Title"))</label>
                        </td>
                        <td>
                            <input type="text" name="title" value="@JDM.String(i.Title)" maxlength="100" />
                        </td>
                    </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Description"))</label>
                    </td>
                    <td>
                        <textarea name="description" maxlength="1000">@JDM.String(i.Description)</textarea>
                    </td>
                </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Text"))</label>
                        </td>
                        <td>
                            <textarea id="@ID("txt_text_{0}", JDM.String(i.Language.Code))" name="text">@Html.Raw(JDM.String(i.Text))</textarea>
                        </td>
                    </tr>
                </table>
                <ul class="bar toolbar">
                    <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
                    <li><a class="button confirm" href="@Url.Action(Loc.Act("DeleteTranslation").Set(new
                    {
                        id = JDM.Int32(i.EntityID), 
                        postID = JDM.Int32(Model.EntityID)
                    }).Localized())">@T(Res.In("Common").Of("Act").Name("Delete"))</a></li>
                </ul>
            </form>
        </div>
    }
    <div id="@ID("tab_new")">
        <script type="text/javascript">
            jQuery(document).ready(function () {
                jQuery('@ID("#form_new")').validate({
                    rules: {
                        title: {
                            required: true
                        }
                    }
                });
                jQuery.ajax({
                    type: 'post',
                    url: '@Url.Action(Loc.Act("Languages").Ctrl("Configuration").NoArea().Localized())',
                    dataType: 'json',
                    success: function (rsp) {
                        var ddl = jQuery('@ID("#ddl_lang_new")');
                        ddl.empty();
                        jQuery.each(rsp, function (k, v) {
                            ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                        });
                    }
                });
                jQuery('@ID("#txt_text_new")').ckeditor({
                    fillSpace: true,
                    autoHeight: false
                });
            });
        </script>
        <form id="@ID("form_new")" class="common-form" action="@Url.Action(Loc.Act("CreateTranslation").Localized())" method="post">
            <input type="hidden" name="postID" value="@JDM.Int32(Model.EntityID)" />
            <table>
                <tr>
                    <td>
                        <label>@T(Res.Name("Language"))</label>
                    </td>
                    <td>
                        <select id="@ID("ddl_lang_new")" name="languageID"></select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Title"))</label>
                    </td>
                    <td>
                        <input type="text" name="title" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Description"))</label>
                    </td>
                    <td>
                        <textarea name="description" maxlength="1000"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Text"))</label>
                    </td>
                    <td>
                        <textarea id="@ID("txt_text_new")" name="text"></textarea>
                    </td>
                </tr>
            </table>
            <ul class="bar toolbar">
                <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
            </ul>
        </form>
    </div>
</div>
